//
//  NSMutableSet+HACShield.m
//  HACShield
//
//  Created by Chengjie on 2019/5/22.
//

#import "NSMutableSet+HACShield.h"
#import "NSObject+HACSwizzling.h"

@implementation NSMutableSet (HACShield)

/**
 __NSSetM
 */
+ (void)load {
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        Class cls = hac_getClass(@"__NSS", @"etM");
        SEL sel_add_obj = @selector(addObject:);
        hac_swizzleInstanceMethod(cls, sel_add_obj, @selector(hac_addObject:));
        SEL sel_add_objs = @selector(addObjectsFromArray:);
        hac_swizzleInstanceMethod(cls, sel_add_objs, @selector(hac_addObjectsFromArray:));
        SEL sel_remove_obj = @selector(removeObject:);
        hac_swizzleInstanceMethod(cls, sel_remove_obj, @selector(hac_removeObject:));
    });

}

- (void)hac_addObject:(id)object{
    if (object) {
        [self hac_addObject:object];
    }
}

- (void)hac_addObjectsFromArray:(NSArray *)array{
    if (array && [array isKindOfClass:[NSArray class]] && array.count > 0) {
        [self hac_addObjectsFromArray:array];
    }
}

- (void)hac_removeObject:(id)object{
    if (object && self.count > 0) {
        [self hac_removeObject:object];
    }
}

@end
